Artificial Intelligence Nanodegree

Computer Vision Capstone

Project: Facial Keypoint Detection


Welcome to the final Computer Vision project in the Artificial Intelligence Nanodegree program!

In this project, you’ll combine your knowledge of computer vision techniques and deep learning to build and end-to-end facial keypoint recognition system! Facial keypoints include points around the eyes, nose, and mouth on any face and are used in many applications, from facial tracking to emotion recognition.

There are three main parts to this project:

Part 1 : Investigating OpenCV, pre-processing, and face detection

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!


*Here's what you need to know to complete the project:

  1. In this notebook, some template code has already been provided for you, and you will need to implement additional functionality to successfully complete this project. You will not need to modify the included code beyond what is requested.

    a. Sections that begin with '(IMPLEMENTATION)' in the header indicate that the following block of code will require additional functionality which you must provide. Instructions will be provided for each section, and the specifics of the implementation are marked in the code block with a 'TODO' statement. Please be sure to read the instructions carefully!

  1. In addition to implementing code, there will be questions that you must answer which relate to the project and your implementation.

    a. Each section where you will answer a question is preceded by a 'Question X' header.

    b. Carefully read each question and provide thorough answers in the following text boxes that begin with 'Answer:'.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. Markdown cells can be edited by double-clicking the cell to enter edit mode.

The rubric contains optional suggestions for enhancing the project beyond the minimum requirements. If you decide to pursue the "(Optional)" sections, you should include the code in this IPython notebook.

Your project submission will be evaluated based on your answers to each of the questions and the code implementations you provide.

Steps to Complete the Project

Each part of the notebook is further broken down into separate steps. Feel free to use the links below to navigate the notebook.

In this project you will get to explore a few of the many computer vision algorithms built into the OpenCV library. This expansive computer vision library is now almost 20 years old and still growing!

The project itself is broken down into three large parts, then even further into separate steps. Make sure to read through each step, and complete any sections that begin with '(IMPLEMENTATION)' in the header; these implementation sections may contain multiple TODOs that will be marked in code. For convenience, we provide links to each of these steps below.

Part 1 : Investigating OpenCV, pre-processing, and face detection

  • Step 0: Detect Faces Using a Haar Cascade Classifier
  • Step 1: Add Eye Detection
  • Step 2: De-noise an Image for Better Face Detection
  • Step 3: Blur an Image and Perform Edge Detection
  • Step 4: Automatically Hide the Identity of an Individual

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

  • Step 5: Create a CNN to Recognize Facial Keypoints
  • Step 6: Compile and Train the Model
  • Step 7: Visualize the Loss and Answer Questions

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!

  • Step 8: Build a Robust Facial Keypoints Detector (Complete the CV Pipeline)

Step 0: Detect Faces Using a Haar Cascade Classifier

Have you ever wondered how Facebook automatically tags images with your friends' faces? Or how high-end cameras automatically find and focus on a certain person's face? Applications like these depend heavily on the machine learning task known as face detection - which is the task of automatically finding faces in images containing people.

At its root face detection is a classification problem - that is a problem of distinguishing between distinct classes of things. With face detection these distinct classes are 1) images of human faces and 2) everything else.

We use OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on github. We have downloaded one of these detectors and stored it in the detector_architectures directory.

Import Resources

In the next python cell, we load in the required libraries for this section of the project.

In [1]:
# Import required libraries for this section

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import math
import cv2                     # OpenCV library for computer vision
from PIL import Image
import time 

Next, we load in and display a test image for performing face detection.

Note: by default OpenCV assumes the ordering of our image's color channels are Blue, then Green, then Red. This is slightly out of order with most image types we'll use in these experiments, whose color channels are ordered Red, then Green, then Blue. In order to switch the Blue and Red channels of our test image around we will use OpenCV's cvtColor function, which you can read more about by checking out some of its documentation located here. This is a general utility function that can do other transformations too like converting a color image to grayscale, and transforming a standard color image to HSV color space.

In [2]:
# Load in color image for face detection
image = cv2.imread('images/test_image_1.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot our image using subplots to specify a size and title
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[2]:
<matplotlib.image.AxesImage at 0x7f9fb7275400>

There are a lot of people - and faces - in this picture. 13 faces to be exact! In the next code cell, we demonstrate how to use a Haar Cascade classifier to detect all the faces in this test image.

This face detector uses information about patterns of intensity in an image to reliably detect faces under varying light conditions. So, to use this face detector, we'll first convert the image from color to grayscale.

Then, we load in the fully trained architecture of the face detector -- found in the file haarcascade_frontalface_default.xml - and use it on our image to find faces!

To learn more about the parameters of the detector see this post.

In [3]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[3]:
<matplotlib.image.AxesImage at 0x7f9fb7219ef0>

In the above code, faces is a numpy array of detected faces, where each row corresponds to a detected face. Each detected face is a 1D array with four entries that specifies the bounding box of the detected face. The first two entries in the array (extracted in the above code as x and y) specify the horizontal and vertical positions of the top left corner of the bounding box. The last two entries in the array (extracted here as w and h) specify the width and height of the box.


Step 1: Add Eye Detections

There are other pre-trained detectors available that use a Haar Cascade Classifier - including full human body detectors, license plate detectors, and more. A full list of the pre-trained architectures can be found here.

To test your eye detector, we'll first read in a new test image with just a single face.

In [20]:
# Load in color image for face detection
image = cv2.imread('images/james.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot the RGB image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[20]:
<matplotlib.image.AxesImage at 0x7f9fac5febe0>

Notice that even though the image is a black and white image, we have read it in as a color image and so it will still need to be converted to grayscale in order to perform the most accurate face detection.

So, the next steps will be to convert this image to grayscale, then load OpenCV's face detector and run it with parameters that detect this face accurately.

In [21]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.25, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_with_detections)
Number of faces detected: 1
Out[21]:
<matplotlib.image.AxesImage at 0x7f9fac5ea6d8>

(IMPLEMENTATION) Add an eye detector to the current face detection setup.

A Haar-cascade eye detector can be included in the same way that the face detector was and, in this first task, it will be your job to do just this.

To set up an eye detector, use the stored parameters of the eye cascade detector, called haarcascade_eye.xml, located in the detector_architectures subdirectory. In the next code cell, create your eye detector and store its detections.

A few notes before you get started:

First, make sure to give your loaded eye detector the variable name

eye_cascade

and give the list of eye regions you detect the variable name

eyes

Second, since we've already run the face detector over this image, you should only search for eyes within the rectangular face regions detected in faces. This will minimize false detections.

Lastly, once you've run your eye detector over the facial detection region, you should display the RGB image with both the face detection boxes (in red) and your eye detections (in green) to verify that everything works as expected.

In [24]:
# Make a copy of the original image to plot rectangle detections
image_with_detections = np.copy(image)   

# Loop over the detections and draw their corresponding face detection boxes
for (x,y,w,h) in faces:
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(255,0,0), 3)  
    
# Do not change the code above this comment!

eyes_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_eye.xml")

if (eyes_cascade is None):
    print("No eyes classifier")
## TODO: Add eye detection, using haarcascade_eye.xml, to the current face detector algorithm
## TODO: Loop over the eye detections and draw their corresponding boxes in green on image_with_detections
for (x,y,w,h) in faces:
    face = gray[y:y+h, x:x+w]
    eyes = eyes_cascade.detectMultiScale(face)
    print("There are {} eyes".format(len(eyes)))
    for (ex, ey, ew, eh) in eyes:
        cv2.rectangle(image_with_detections, (ex + x, ey + y), (ex+ew+x, ey+eh+y), (0,255,0), 3)

# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face and Eye Detection')
ax1.imshow(image_with_detections)
There are 2 eyes
Out[24]:
<matplotlib.image.AxesImage at 0x7f9fac457128>

(Optional) Add face and eye detection to your laptop camera

It's time to kick it up a notch, and add face and eye detection to your laptop's camera! Afterwards, you'll be able to show off your creation like in the gif shown below - made with a completed version of the code!

<img src="images/laptop_face_detector_example.gif" width=400 height=300/>

Notice that not all of the detections here are perfect - and your result need not be perfect either. You should spend a small amount of time tuning the parameters of your detectors to get reasonable results, but don't hold out for perfection. If we wanted perfection we'd need to spend a ton of time tuning the parameters of each detector, cleaning up the input image frames, etc. You can think of this as more of a rapid prototype.

The next cell contains code for a wrapper function called laptop_camera_face_eye_detector that, when called, will activate your laptop's camera. You will place the relevant face and eye detection code in this wrapper function to implement face/eye detection and mark those detections on each image frame that your camera captures.

Before adding anything to the function, you can run it to get an idea of how it works - a small window should pop up showing you the live feed from your camera; you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [25]:
### Add face and eye detection to this laptop camera function 
# Make sure to draw out all faces/eyes found in each frame on the shown video feed

import cv2
import time 

# wrapper function for face/eye detection with your laptop camera
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)
    
    face_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")
    eyes_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_eye.xml")
    
    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep the video stream open
    while rval:
        
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.25, 6)
        
        for (x, y, w, h) in faces:
            roi = gray[x:x+w, y:y+h]
            eyes = eyes_cascade.detectMultiScale(roi)
            cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
            for (ex, ey, ew, eh) in eyes:
                cv2.rectangle(roi, (ex+x, ey+y), (ex+ew+x, ey+eh+y), (0, 255, 0), 2)
        
        # Plot the image from camera with all the face and eye detections marked
        cv2.imshow("face detection activated", frame)
             # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            # Make sure window closes on OSx
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
In [26]:
# Call the laptop camera face/eye detector function above
laptop_camera_go()
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-26-6947bd6b284f> in <module>()
      1 # Call the laptop camera face/eye detector function above
----> 2 laptop_camera_go()

<ipython-input-25-c512b67dc904> in laptop_camera_go()
      8 def laptop_camera_go():
      9     # Create instance of video capturer
---> 10     cv2.namedWindow("face detection activated")
     11     vc = cv2.VideoCapture(0)
     12 

error: /io/opencv/modules/highgui/src/window.cpp:565: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

Step 2: De-noise an Image for Better Face Detection

Image quality is an important aspect of any computer vision task. Typically, when creating a set of images to train a deep learning network, significant care is taken to ensure that training images are free of visual noise or artifacts that hinder object detection. While computer vision algorithms - like a face detector - are typically trained on 'nice' data such as this, new test data doesn't always look so nice!

When applying a trained computer vision algorithm to a new piece of test data one often cleans it up first before feeding it in. This sort of cleaning - referred to as pre-processing - can include a number of cleaning phases like blurring, de-noising, color transformations, etc., and many of these tasks can be accomplished using OpenCV.

In this short subsection we explore OpenCV's noise-removal functionality to see how we can clean up a noisy image, which we then feed into our trained face detector.

Create a noisy image to work with

In the next cell, we create an artificial noisy version of the previous multi-face image. This is a little exaggerated - we don't typically get images that are this noisy - but image noise, or 'grainy-ness' in a digitial image - is a fairly common phenomenon.

In [9]:
# Load in the multi-face test image again
image = cv2.imread('images/test_image_1.jpg')

# Convert the image copy to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Make an array copy of this image
image_with_noise = np.asarray(image)

# Create noise - here we add noise sampled randomly from a Gaussian distribution: a common model for noise
noise_level = 40
noise = np.random.randn(image.shape[0],image.shape[1],image.shape[2])*noise_level

# Add this noise to the array image copy
image_with_noise = image_with_noise + noise

# Convert back to uint8 format
image_with_noise = np.asarray([np.uint8(np.clip(i,0,255)) for i in image_with_noise])

# Plot our noisy image!
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image')
ax1.imshow(image_with_noise)
Out[9]:
<matplotlib.image.AxesImage at 0x7f9fb67eb128>

In the context of face detection, the problem with an image like this is that - due to noise - we may miss some faces or get false detections.

In the next cell we apply the same trained OpenCV detector with the same settings as before, to see what sort of detections we get.

In [10]:
# Convert the RGB  image to grayscale
gray_noise = cv2.cvtColor(image_with_noise, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_noise, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_with_noise)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 12
Out[10]:
<matplotlib.image.AxesImage at 0x7f9fb42f3b70>

With this added noise we now miss one of the faces!

(IMPLEMENTATION) De-noise this image for better face detection

Time to get your hands dirty: using OpenCV's built in color image de-noising functionality called fastNlMeansDenoisingColored - de-noise this image enough so that all the faces in the image are properly detected. Once you have cleaned the image in the next cell, use the cell that follows to run our trained face detector over the cleaned image to check out its detections.

You can find its official documentation here and a useful example here.

Note: you can keep all parameters except photo_render fixed as shown in the second link above. Play around with the value of this parameter - see how it affects the resulting cleaned image.

In [11]:
## TODO: Use OpenCV's built in color image de-noising function to clean up our noisy image!


#denoised_image = # your final de-noised image (should be RGB)
denoised_image = cv2.fastNlMeansDenoisingColored(image_with_noise, None, 17, 17, 7, 21)
# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (8, 8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Denoised image')
ax1.imshow(denoised_image)
Out[11]:
<matplotlib.image.AxesImage at 0x7f9fb42834a8>
In [12]:
## TODO: Run the face detector on the de-noised image to improve your detections and display the result
faces = face_cascade.detectMultiScale(denoised_image, 1.25, 6)
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(denoised_image, (x,y), (x+w,y+h), (255,0,0), 3)
# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (8, 8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Denoised image')
ax1.imshow(denoised_image)
Out[12]:
<matplotlib.image.AxesImage at 0x7f9fb4264940>

Step 3: Blur an Image and Perform Edge Detection

Now that we have developed a simple pipeline for detecting faces using OpenCV - let's start playing around with a few fun things we can do with all those detected faces!

Importance of Blur in Edge Detection

Edge detection is a concept that pops up almost everywhere in computer vision applications, as edge-based features (as well as features built on top of edges) are often some of the best features for e.g., object detection and recognition problems.

Edge detection is a dimension reduction technique - by keeping only the edges of an image we get to throw away a lot of non-discriminating information. And typically the most useful kind of edge-detection is one that preserves only the important, global structures (ignoring local structures that aren't very discriminative). So removing local structures / retaining global structures is a crucial pre-processing step to performing edge detection in an image, and blurring can do just that.

Below is an animated gif showing the result of an edge-detected cat taken from Wikipedia, where the image is gradually blurred more and more prior to edge detection. When the animation begins you can't quite make out what it's a picture of, but as the animation evolves and local structures are removed via blurring the cat becomes visible in the edge-detected image.

<img src="images/Edge_Image.gif" width=400 height=300/>

Edge detection is a convolution performed on the image itself, and you can read about Canny edge detection on this OpenCV documentation page.

Canny edge detection

In the cell below we load in a test image, then apply Canny edge detection on it. The original image is shown on the left panel of the figure, while the edge-detected version of the image is shown on the right. Notice how the result looks very busy - there are too many little details preserved in the image before it is sent to the edge detector. When applied in computer vision applications, edge detection should preserve global structure; doing away with local structures that don't help describe what objects are in the image.

In [13]:
# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[13]:
<matplotlib.image.AxesImage at 0x7f9fb414e668>

Without first blurring the image, and removing small, local structures, a lot of irrelevant edge content gets picked up and amplified by the detector (as shown in the right panel above).

(IMPLEMENTATION) Blur the image then perform edge detection

In the next cell, you will repeat this experiment - blurring the image first to remove these local structures, so that only the important boudnary details remain in the edge-detected image.

Blur the image by using OpenCV's filter2d functionality - which is discussed in this documentation page - and use an averaging kernel of width equal to 4.

In [14]:
### TODO: Blur the test imageusing OpenCV's filter2d functionality, 
# Use an averaging kernel, and a kernel width equal to 4

image = cv2.imread('images/fawzia.jpg')

image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  
kernel = np.array([
    [1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1]
])
gray = cv2.filter2D(gray, -1, kernel)

## TODO: Then perform Canny edge detection and display the output

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[14]:
<matplotlib.image.AxesImage at 0x7f9fb40506a0>

Step 4: Automatically Hide the Identity of an Individual

If you film something like a documentary or reality TV, you must get permission from every individual shown on film before you can show their face, otherwise you need to blur it out - by blurring the face a lot (so much so that even the global structures are obscured)! This is also true for projects like Google's StreetView maps - an enormous collection of mapping images taken from a fleet of Google vehicles. Because it would be impossible for Google to get the permission of every single person accidentally captured in one of these images they blur out everyone's faces, the detected images must automatically blur the identity of detected people. Here's a few examples of folks caught in the camera of a Google street view vehicle.

<img src="images/streetview_example_1.jpg" width=400 height=300/> <img src="images/streetview_example_2.jpg" width=400 height=300/>

Read in an image to perform identity detection

Let's try this out for ourselves. Use the face detection pipeline built above and what you know about using the filter2D to blur and image, and use these in tandem to hide the identity of the person in the following image - loaded in and printed in the next cell.

In [15]:
# Load in the image
image = cv2.imread('images/gus.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[15]:
<matplotlib.image.AxesImage at 0x7f9fac7f0860>

(IMPLEMENTATION) Use blurring to hide the identity of an individual in an image

The idea here is to 1) automatically detect the face in this image, and then 2) blur it out! Make sure to adjust the parameters of the averaging blur filter to completely obscure this person's identity.

In [16]:
## TODO: Implement face detection
image = cv2.imread("images/gus.jpg")
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face_c = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")
faces = face_c.detectMultiScale(gray)
print("found {} faces".format(len(faces)))
kernel = np.array([
    [1, 1, 1],
    [1, 1, 1],
    [1, 1, 1]
])

## TODO: Blur the bounding box around each detected face using an averaging filter and display the result
for (x, y, w, h) in faces:
    # discard small faces as they are mistakes
    if (w < 200):
        continue
    print("processing face... {} {} {} {} ".format(x, y, w, h))
    roi = image[y:y+h, x:x+w]
    # i'm using GaussianBlur instead of using filter2D with the above kernel
    roi = cv2.GaussianBlur(roi, (71, 71), 20, 20)
    image[y:y+h, x:x+w] = roi

# Display the image
fig = plt.figure(figsize = (9, 9))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
found 5 faces
processing face... 766 86 411 411 
Out[16]:
<matplotlib.image.AxesImage at 0x7f9fac709a90>

(Optional) Build identity protection into your laptop camera

In this optional task you can add identity protection to your laptop camera, using the previously completed code where you added face detection to your laptop camera - and the task above. You should be able to get reasonable results with little parameter tuning - like the one shown in the gif below.

<img src="images/laptop_blurer_example.gif" width=400 height=300/>

As with the previous video task, to make this perfect would require significant effort - so don't strive for perfection here, strive for reasonable quality.

The next cell contains code a wrapper function called laptop_camera_identity_hider that - when called - will activate your laptop's camera. You need to place the relevant face detection and blurring code developed above in this function in order to blur faces entering your laptop camera's field of view.

Before adding anything to the function you can call it to get a hang of how it works - a small window will pop up showing you the live feed from your camera, you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [17]:
### Insert face detection and blurring code into the wrapper below to create an identity protector on your laptop!
import cv2
import time 

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)
    face_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")
    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.25, 6)
        for (x, y, w, h) in faces:
            roi = frame[y:y+h, x:x+w]
            roi = cv2.GaussianBlur(roi, (71, 71), 50, 50)
            frame[y:y+h, x:x+w] = roi
            
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [18]:
# Run laptop identity hider
laptop_camera_go()
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-18-980123c929f8> in <module>()
      1 # Run laptop identity hider
----> 2 laptop_camera_go()

<ipython-input-17-aa5803216ee0> in laptop_camera_go()
      5 def laptop_camera_go():
      6     # Create instance of video capturer
----> 7     cv2.namedWindow("face detection activated")
      8     vc = cv2.VideoCapture(0)
      9     face_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")

error: /io/opencv/modules/highgui/src/window.cpp:565: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

Step 5: Create a CNN to Recognize Facial Keypoints

OpenCV is often used in practice with other machine learning and deep learning libraries to produce interesting results. In this stage of the project you will create your own end-to-end pipeline - employing convolutional networks in keras along with OpenCV - to apply a "selfie" filter to streaming video and images.

You will start by creating and then training a convolutional network that can detect facial keypoints in a small dataset of cropped images of human faces. We then guide you towards OpenCV to expanding your detection algorithm to more general images. What are facial keypoints? Let's take a look at some examples.

<img src="images/keypoints_test_results.png" width=400 height=300/>

Facial keypoints (also called facial landmarks) are the small blue-green dots shown on each of the faces in the image above - there are 15 keypoints marked in each image. They mark important areas of the face - the eyes, corners of the mouth, the nose, etc. Facial keypoints can be used in a variety of machine learning applications from face and emotion recognition to commercial applications like the image filters popularized by Snapchat.

Below we illustrate a filter that, using the results of this section, automatically places sunglasses on people in images (using the facial keypoints to place the glasses correctly on each face). Here, the facial keypoints have been colored lime green for visualization purposes.

<img src="images/obamas_with_shades.png" width=1000 height=1000/>

Make a facial keypoint detector

But first things first: how can we make a facial keypoint detector? Well, at a high level, notice that facial keypoint detection is a regression problem. A single face corresponds to a set of 15 facial keypoints (a set of 15 corresponding $(x, y)$ coordinates, i.e., an output point). Because our input data are images, we can employ a convolutional neural network to recognize patterns in our images and learn how to identify these keypoint given sets of labeled data.

In order to train a regressor, we need a training set - a set of facial image / facial keypoint pairs to train on. For this we will be using this dataset from Kaggle. We've already downloaded this data and placed it in the data directory. Make sure that you have both the training and test data files. The training dataset contains several thousand $96 \times 96$ grayscale images of cropped human faces, along with each face's 15 corresponding facial keypoints (also called landmarks) that have been placed by hand, and recorded in $(x, y)$ coordinates. This wonderful resource also has a substantial testing set, which we will use in tinkering with our convolutional network.

To load in this data, run the Python cell below - notice we will load in both the training and testing sets.

The load_data function is in the included utils.py file.

In [28]:
from utils import *

# Load training set
X_train, y_train = load_data()
print("X_train.shape == {}".format(X_train.shape))
print("y_train.shape == {}; y_train.min == {:.3f}; y_train.max == {:.3f}".format(
    y_train.shape, y_train.min(), y_train.max()))

# Load testing set
X_test, _ = load_data(test=True)
print("X_test.shape == {}".format(X_test.shape))
X_train.shape == (2140, 96, 96, 1)
y_train.shape == (2140, 30); y_train.min == -0.920; y_train.max == 0.996
X_test.shape == (1783, 96, 96, 1)

The load_data function in utils.py originates from this excellent blog post, which you are strongly encouraged to read. Please take the time now to review this function. Note how the output values - that is, the coordinates of each set of facial landmarks - have been normalized to take on values in the range $[-1, 1]$, while the pixel values of each input point (a facial image) have been normalized to the range $[0,1]$.

Note: the original Kaggle dataset contains some images with several missing keypoints. For simplicity, the load_data function removes those images with missing labels from the dataset. As an optional extension, you are welcome to amend the load_data function to include the incomplete data points.

Visualize the Training Data

Execute the code cell below to visualize a subset of the training data.

In [29]:
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_train[i], y_train[i], ax)

For each training image, there are two landmarks per eyebrow (four total), three per eye (six total), four for the mouth, and one for the tip of the nose.

Review the plot_data function in utils.py to understand how the 30-dimensional training labels in y_train are mapped to facial locations, as this function will prove useful for your pipeline.

(IMPLEMENTATION) Specify the CNN Architecture

In this section, you will specify a neural network for predicting the locations of facial keypoints. Use the code cell below to specify the architecture of your neural network. We have imported some layers that you may find useful for this task, but if you need to use more Keras layers, feel free to import them in the cell.

Your network should accept a $96 \times 96$ grayscale image as input, and it should output a vector with 30 entries, corresponding to the predicted (horizontal and vertical) locations of 15 facial keypoints. If you are not sure where to start, you can find some useful starting architectures in this blog, but you are not permitted to copy any of the architectures that you find online.

In [33]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, GlobalAveragePooling2D
from keras.layers import Flatten, Dense, Activation
from keras.layers.normalization import BatchNormalization


## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)

model = Sequential()
model.add(Conv2D(40, kernel_size=7, padding="same", input_shape=X_train.shape[1:]))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.2))
model.add(Conv2D(80, kernel_size=5, padding="same"))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.2))
model.add(Conv2D(160, kernel_size=3, padding="same"))
model.add(MaxPooling2D(pool_size=2))

model.add(GlobalAveragePooling2D())
model.add(Dense(300))
model.add(Dropout(0.2))
model.add(Dense(30))


# Summarize the model
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_4 (Conv2D)            (None, 96, 96, 40)        2000      
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 48, 48, 40)        0         
_________________________________________________________________
dropout_4 (Dropout)          (None, 48, 48, 40)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 48, 48, 80)        80080     
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 24, 24, 80)        0         
_________________________________________________________________
dropout_5 (Dropout)          (None, 24, 24, 80)        0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 24, 24, 160)       115360    
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 12, 12, 160)       0         
_________________________________________________________________
global_average_pooling2d_2 ( (None, 160)               0         
_________________________________________________________________
dense_3 (Dense)              (None, 300)               48300     
_________________________________________________________________
dropout_6 (Dropout)          (None, 300)               0         
_________________________________________________________________
dense_4 (Dense)              (None, 30)                9030      
=================================================================
Total params: 254,770
Trainable params: 254,770
Non-trainable params: 0
_________________________________________________________________

Step 6: Compile and Train the Model

After specifying your architecture, you'll need to compile and train the model to detect facial keypoints'

(IMPLEMENTATION) Compile and Train the Model

Use the compile method to configure the learning process. Experiment with your choice of optimizer; you may have some ideas about which will work best (SGD vs. RMSprop, etc), but take the time to empirically verify your theories.

Use the fit method to train the model. Break off a validation set by setting validation_split=0.2. Save the returned History object in the history variable.

Your model is required to attain a validation loss (measured as mean squared error) of at least XYZ. When you have finished training, save your model as an HDF5 file with file path my_model.h5.

In [34]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam

## TODO: Compile the model

from keras.callbacks import ModelCheckpoint  

checkpointer = ModelCheckpoint(filepath='my_model.h5', verbose=1, save_best_only=True)
model.compile(optimizer='adamax', loss="mean_squared_error", metrics=['accuracy'])

## TODO: Train the model
hist = model.fit(X_train, y_train, batch_size=32, epochs=300, verbose=1, validation_split=0.2, callbacks=[checkpointer])

## TODO: Save the model as model.h5
model.save('my_model.h5')
Train on 1712 samples, validate on 428 samples
Epoch 1/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0195 - acc: 0.5142Epoch 00000: val_loss improved from inf to 0.01445, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0194 - acc: 0.5134 - val_loss: 0.0145 - val_acc: 0.6963
Epoch 2/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0077 - acc: 0.6038Epoch 00001: val_loss improved from 0.01445 to 0.00886, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0077 - acc: 0.6046 - val_loss: 0.0089 - val_acc: 0.6963
Epoch 3/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0067 - acc: 0.6356Epoch 00002: val_loss improved from 0.00886 to 0.00864, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0067 - acc: 0.6338 - val_loss: 0.0086 - val_acc: 0.6939
Epoch 4/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0065 - acc: 0.6468Epoch 00003: val_loss improved from 0.00864 to 0.00733, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0065 - acc: 0.6466 - val_loss: 0.0073 - val_acc: 0.6963
Epoch 5/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0061 - acc: 0.6392Epoch 00004: val_loss improved from 0.00733 to 0.00594, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0061 - acc: 0.6390 - val_loss: 0.0059 - val_acc: 0.6963
Epoch 6/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0060 - acc: 0.6421Epoch 00005: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0060 - acc: 0.6419 - val_loss: 0.0089 - val_acc: 0.6963
Epoch 7/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0058 - acc: 0.6551Epoch 00006: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0058 - acc: 0.6554 - val_loss: 0.0086 - val_acc: 0.6963
Epoch 8/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0057 - acc: 0.6580Epoch 00007: val_loss improved from 0.00594 to 0.00573, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0057 - acc: 0.6577 - val_loss: 0.0057 - val_acc: 0.6963
Epoch 9/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0056 - acc: 0.6675Epoch 00008: val_loss improved from 0.00573 to 0.00478, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0056 - acc: 0.6676 - val_loss: 0.0048 - val_acc: 0.6963
Epoch 10/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0056 - acc: 0.6675Epoch 00009: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0056 - acc: 0.6653 - val_loss: 0.0054 - val_acc: 0.6963
Epoch 11/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0055 - acc: 0.6728Epoch 00010: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0055 - acc: 0.6741 - val_loss: 0.0048 - val_acc: 0.6963
Epoch 12/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0053 - acc: 0.6769Epoch 00011: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0053 - acc: 0.6770 - val_loss: 0.0059 - val_acc: 0.6963
Epoch 13/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0053 - acc: 0.6834Epoch 00012: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0052 - acc: 0.6828 - val_loss: 0.0051 - val_acc: 0.6963
Epoch 14/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0052 - acc: 0.6828Epoch 00013: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0052 - acc: 0.6811 - val_loss: 0.0049 - val_acc: 0.6963
Epoch 15/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0052 - acc: 0.6840Epoch 00014: val_loss improved from 0.00478 to 0.00431, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0052 - acc: 0.6834 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 16/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0051 - acc: 0.6834Epoch 00015: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0051 - acc: 0.6828 - val_loss: 0.0044 - val_acc: 0.6963
Epoch 17/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0050 - acc: 0.6792Epoch 00016: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0050 - acc: 0.6811 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 18/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0050 - acc: 0.6840Epoch 00017: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0050 - acc: 0.6822 - val_loss: 0.0046 - val_acc: 0.6963
Epoch 19/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0050 - acc: 0.6893Epoch 00018: val_loss improved from 0.00431 to 0.00429, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0050 - acc: 0.6893 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 20/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - acc: 0.6899Epoch 00019: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0049 - acc: 0.6893 - val_loss: 0.0044 - val_acc: 0.6963
Epoch 21/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0049 - acc: 0.6987Epoch 00020: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0049 - acc: 0.6980 - val_loss: 0.0044 - val_acc: 0.6963
Epoch 22/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - acc: 0.6952Epoch 00021: val_loss improved from 0.00429 to 0.00416, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0048 - acc: 0.6968 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 23/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - acc: 0.6904Epoch 00022: val_loss improved from 0.00416 to 0.00416, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0048 - acc: 0.6922 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 24/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - acc: 0.6928Epoch 00023: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0048 - acc: 0.6916 - val_loss: 0.0045 - val_acc: 0.6963
Epoch 25/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0048 - acc: 0.6946Epoch 00024: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0048 - acc: 0.6945 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 26/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0047 - acc: 0.6822Epoch 00025: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0047 - acc: 0.6834 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 27/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.6963Epoch 00026: val_loss improved from 0.00416 to 0.00416, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0046 - acc: 0.6968 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 28/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0047 - acc: 0.6981Epoch 00027: val_loss improved from 0.00416 to 0.00407, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0047 - acc: 0.7004 - val_loss: 0.0041 - val_acc: 0.6963
Epoch 29/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.6975Epoch 00028: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0046 - acc: 0.6992 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 30/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0045 - acc: 0.6940Epoch 00029: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0045 - acc: 0.6945 - val_loss: 0.0044 - val_acc: 0.6963
Epoch 31/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0045 - acc: 0.7005Epoch 00030: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0045 - acc: 0.7004 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 32/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - acc: 0.6999Epoch 00031: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0044 - acc: 0.6974 - val_loss: 0.0048 - val_acc: 0.6963
Epoch 33/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0044 - acc: 0.7011Epoch 00032: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0044 - acc: 0.7009 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 34/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0043 - acc: 0.6946Epoch 00033: val_loss improved from 0.00407 to 0.00398, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0043 - acc: 0.6945 - val_loss: 0.0040 - val_acc: 0.6963
Epoch 35/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0043 - acc: 0.6969Epoch 00034: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0043 - acc: 0.6963 - val_loss: 0.0042 - val_acc: 0.6963
Epoch 36/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0042 - acc: 0.6993Epoch 00035: val_loss improved from 0.00398 to 0.00380, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0042 - acc: 0.6998 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 37/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0042 - acc: 0.7028Epoch 00036: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0042 - acc: 0.7033 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 38/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0041 - acc: 0.7017Epoch 00037: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0041 - acc: 0.7039 - val_loss: 0.0039 - val_acc: 0.6963
Epoch 39/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0040 - acc: 0.7028Epoch 00038: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0040 - acc: 0.7039 - val_loss: 0.0049 - val_acc: 0.6963
Epoch 40/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0039 - acc: 0.7022Epoch 00039: val_loss improved from 0.00380 to 0.00355, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0039 - acc: 0.7009 - val_loss: 0.0036 - val_acc: 0.6963
Epoch 41/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0040 - acc: 0.7046Epoch 00040: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0040 - acc: 0.7050 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 42/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0038 - acc: 0.7064Epoch 00041: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0038 - acc: 0.7062 - val_loss: 0.0040 - val_acc: 0.6963
Epoch 43/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0039 - acc: 0.6981Epoch 00042: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0039 - acc: 0.6986 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 44/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0038 - acc: 0.7052Epoch 00043: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0038 - acc: 0.7062 - val_loss: 0.0037 - val_acc: 0.6963
Epoch 45/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0038 - acc: 0.7058Epoch 00044: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0037 - acc: 0.7068 - val_loss: 0.0038 - val_acc: 0.6963
Epoch 46/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0037 - acc: 0.7011Epoch 00045: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0037 - acc: 0.7009 - val_loss: 0.0036 - val_acc: 0.6963
Epoch 47/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0036 - acc: 0.7040Epoch 00046: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0036 - acc: 0.7044 - val_loss: 0.0043 - val_acc: 0.6963
Epoch 48/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0036 - acc: 0.7052Epoch 00047: val_loss improved from 0.00355 to 0.00334, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0036 - acc: 0.7056 - val_loss: 0.0033 - val_acc: 0.6963
Epoch 49/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0035 - acc: 0.7005Epoch 00048: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0035 - acc: 0.7004 - val_loss: 0.0036 - val_acc: 0.6986
Epoch 50/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0034 - acc: 0.6981Epoch 00049: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0034 - acc: 0.6974 - val_loss: 0.0037 - val_acc: 0.6986
Epoch 51/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0035 - acc: 0.7105Epoch 00050: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0035 - acc: 0.7109 - val_loss: 0.0037 - val_acc: 0.6986
Epoch 52/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0034 - acc: 0.7017Epoch 00051: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0034 - acc: 0.7009 - val_loss: 0.0035 - val_acc: 0.6963
Epoch 53/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0035 - acc: 0.7064Epoch 00052: val_loss improved from 0.00334 to 0.00308, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0035 - acc: 0.7044 - val_loss: 0.0031 - val_acc: 0.6963
Epoch 54/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0033 - acc: 0.7011Epoch 00053: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0033 - acc: 0.7015 - val_loss: 0.0039 - val_acc: 0.6963
Epoch 55/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0034 - acc: 0.6952Epoch 00054: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0033 - acc: 0.6968 - val_loss: 0.0037 - val_acc: 0.6986
Epoch 56/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0032 - acc: 0.7052Epoch 00055: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0032 - acc: 0.7050 - val_loss: 0.0032 - val_acc: 0.6986
Epoch 57/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0032 - acc: 0.6993Epoch 00056: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0032 - acc: 0.6992 - val_loss: 0.0035 - val_acc: 0.6986
Epoch 58/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0032 - acc: 0.7028Epoch 00057: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0032 - acc: 0.7033 - val_loss: 0.0039 - val_acc: 0.7033
Epoch 59/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0032 - acc: 0.7099Epoch 00058: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0032 - acc: 0.7085 - val_loss: 0.0031 - val_acc: 0.7126
Epoch 60/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0031 - acc: 0.7028Epoch 00059: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0031 - acc: 0.7033 - val_loss: 0.0036 - val_acc: 0.7103
Epoch 61/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0030 - acc: 0.7081Epoch 00060: val_loss improved from 0.00308 to 0.00292, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0030 - acc: 0.7079 - val_loss: 0.0029 - val_acc: 0.7079
Epoch 62/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0031 - acc: 0.6952Epoch 00061: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0031 - acc: 0.6951 - val_loss: 0.0034 - val_acc: 0.7009
Epoch 63/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0031 - acc: 0.7011Epoch 00062: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0031 - acc: 0.7009 - val_loss: 0.0032 - val_acc: 0.7009
Epoch 64/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0030 - acc: 0.7005Epoch 00063: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0030 - acc: 0.7004 - val_loss: 0.0035 - val_acc: 0.7103
Epoch 65/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0029 - acc: 0.7081Epoch 00064: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0029 - acc: 0.7074 - val_loss: 0.0035 - val_acc: 0.7150
Epoch 66/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0030 - acc: 0.7046Epoch 00065: val_loss improved from 0.00292 to 0.00281, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0030 - acc: 0.7039 - val_loss: 0.0028 - val_acc: 0.7150
Epoch 67/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0029 - acc: 0.7129Epoch 00066: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0029 - acc: 0.7126 - val_loss: 0.0035 - val_acc: 0.7103
Epoch 68/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0029 - acc: 0.7123Epoch 00067: val_loss improved from 0.00281 to 0.00281, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0029 - acc: 0.7126 - val_loss: 0.0028 - val_acc: 0.7103
Epoch 69/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7105Epoch 00068: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0028 - acc: 0.7126 - val_loss: 0.0030 - val_acc: 0.7196
Epoch 70/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7040Epoch 00069: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0028 - acc: 0.7056 - val_loss: 0.0030 - val_acc: 0.7079
Epoch 71/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7140Epoch 00070: val_loss improved from 0.00281 to 0.00280, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0028 - acc: 0.7144 - val_loss: 0.0028 - val_acc: 0.7103
Epoch 72/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7105Epoch 00071: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0027 - acc: 0.7114 - val_loss: 0.0029 - val_acc: 0.7079
Epoch 73/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7176Epoch 00072: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0028 - acc: 0.7155 - val_loss: 0.0031 - val_acc: 0.7266
Epoch 74/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0027 - acc: 0.7099Epoch 00073: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0027 - acc: 0.7091 - val_loss: 0.0031 - val_acc: 0.7079
Epoch 75/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7152Epoch 00074: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0026 - acc: 0.7167 - val_loss: 0.0029 - val_acc: 0.7196
Epoch 76/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0027 - acc: 0.7093Epoch 00075: val_loss improved from 0.00280 to 0.00268, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0027 - acc: 0.7091 - val_loss: 0.0027 - val_acc: 0.7313
Epoch 77/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7158Epoch 00076: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0026 - acc: 0.7150 - val_loss: 0.0028 - val_acc: 0.7266
Epoch 78/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7199Epoch 00077: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0026 - acc: 0.7208 - val_loss: 0.0032 - val_acc: 0.7383
Epoch 79/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7034Epoch 00078: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0026 - acc: 0.7027 - val_loss: 0.0027 - val_acc: 0.7150
Epoch 80/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7158Epoch 00079: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7144 - val_loss: 0.0033 - val_acc: 0.7126
Epoch 81/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7252Epoch 00080: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7261 - val_loss: 0.0027 - val_acc: 0.7290
Epoch 82/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7158Epoch 00081: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7138 - val_loss: 0.0027 - val_acc: 0.7126
Epoch 83/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7288Epoch 00082: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7290 - val_loss: 0.0036 - val_acc: 0.7290
Epoch 84/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7229Epoch 00083: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0026 - acc: 0.7231 - val_loss: 0.0035 - val_acc: 0.7220
Epoch 85/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7223Epoch 00084: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7220 - val_loss: 0.0031 - val_acc: 0.7056
Epoch 86/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7182Epoch 00085: val_loss did not improve
1712/1712 [==============================] - 2s - loss: 0.0024 - acc: 0.7185 - val_loss: 0.0028 - val_acc: 0.7336
Epoch 87/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7211Epoch 00086: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0025 - acc: 0.7225 - val_loss: 0.0027 - val_acc: 0.7290
Epoch 88/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7211Epoch 00087: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0024 - acc: 0.7202 - val_loss: 0.0032 - val_acc: 0.7383
Epoch 89/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7276Epoch 00088: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0024 - acc: 0.7278 - val_loss: 0.0029 - val_acc: 0.7383
Epoch 90/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7199Epoch 00089: val_loss improved from 0.00268 to 0.00257, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0024 - acc: 0.7208 - val_loss: 0.0026 - val_acc: 0.7196
Epoch 91/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7294Epoch 00090: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0023 - acc: 0.7301 - val_loss: 0.0029 - val_acc: 0.7220
Epoch 92/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7347Epoch 00091: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0023 - acc: 0.7336 - val_loss: 0.0028 - val_acc: 0.7360
Epoch 93/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7347Epoch 00092: val_loss improved from 0.00257 to 0.00235, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0023 - acc: 0.7331 - val_loss: 0.0023 - val_acc: 0.7383
Epoch 94/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7323Epoch 00093: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0022 - acc: 0.7313 - val_loss: 0.0026 - val_acc: 0.7383
Epoch 95/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7241Epoch 00094: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0023 - acc: 0.7231 - val_loss: 0.0030 - val_acc: 0.7243
Epoch 96/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7241Epoch 00095: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0024 - acc: 0.7255 - val_loss: 0.0027 - val_acc: 0.7173
Epoch 97/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7252Epoch 00096: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0022 - acc: 0.7243 - val_loss: 0.0024 - val_acc: 0.7243
Epoch 98/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7323Epoch 00097: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0021 - acc: 0.7336 - val_loss: 0.0024 - val_acc: 0.7313
Epoch 99/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7217Epoch 00098: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0022 - acc: 0.7231 - val_loss: 0.0024 - val_acc: 0.7336
Epoch 100/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7412Epoch 00099: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0022 - acc: 0.7424 - val_loss: 0.0032 - val_acc: 0.7290
Epoch 101/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7358Epoch 00100: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0022 - acc: 0.7348 - val_loss: 0.0029 - val_acc: 0.7430
Epoch 102/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7317Epoch 00101: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0021 - acc: 0.7313 - val_loss: 0.0025 - val_acc: 0.7126
Epoch 103/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7235Epoch 00102: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0021 - acc: 0.7243 - val_loss: 0.0029 - val_acc: 0.7290
Epoch 104/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7305Epoch 00103: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0021 - acc: 0.7301 - val_loss: 0.0024 - val_acc: 0.7313
Epoch 105/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7246Epoch 00104: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7261 - val_loss: 0.0025 - val_acc: 0.7290
Epoch 106/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7317Epoch 00105: val_loss improved from 0.00235 to 0.00233, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7325 - val_loss: 0.0023 - val_acc: 0.7313
Epoch 107/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7317Epoch 00106: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7319 - val_loss: 0.0030 - val_acc: 0.7336
Epoch 108/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7258Epoch 00107: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7272 - val_loss: 0.0027 - val_acc: 0.7336
Epoch 109/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7188Epoch 00108: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0021 - acc: 0.7185 - val_loss: 0.0028 - val_acc: 0.7033
Epoch 110/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7276Epoch 00109: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7272 - val_loss: 0.0024 - val_acc: 0.7220
Epoch 111/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7129Epoch 00110: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7144 - val_loss: 0.0028 - val_acc: 0.7220
Epoch 112/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7347Epoch 00111: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7348 - val_loss: 0.0025 - val_acc: 0.7196
Epoch 113/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7423Epoch 00112: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0020 - acc: 0.7424 - val_loss: 0.0027 - val_acc: 0.7290
Epoch 114/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7412Epoch 00113: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7418 - val_loss: 0.0025 - val_acc: 0.7336
Epoch 115/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7423Epoch 00114: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7401 - val_loss: 0.0024 - val_acc: 0.7266
Epoch 116/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7412Epoch 00115: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7418 - val_loss: 0.0024 - val_acc: 0.7383
Epoch 117/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7353Epoch 00116: val_loss improved from 0.00233 to 0.00226, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7366 - val_loss: 0.0023 - val_acc: 0.7290
Epoch 118/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7417Epoch 00117: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7418 - val_loss: 0.0031 - val_acc: 0.7243
Epoch 119/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7394Epoch 00118: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7383 - val_loss: 0.0025 - val_acc: 0.7336
Epoch 120/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7294Epoch 00119: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7296 - val_loss: 0.0025 - val_acc: 0.7336
Epoch 121/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7364Epoch 00120: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7354 - val_loss: 0.0024 - val_acc: 0.7313
Epoch 122/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7388Epoch 00121: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7377 - val_loss: 0.0025 - val_acc: 0.7360
Epoch 123/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7412Epoch 00122: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7418 - val_loss: 0.0024 - val_acc: 0.7360
Epoch 124/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7441Epoch 00123: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7407 - val_loss: 0.0023 - val_acc: 0.7313
Epoch 125/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7465Epoch 00124: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7477 - val_loss: 0.0023 - val_acc: 0.7336
Epoch 126/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7465Epoch 00125: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0019 - acc: 0.7465 - val_loss: 0.0023 - val_acc: 0.7407
Epoch 127/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7347Epoch 00126: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7360 - val_loss: 0.0023 - val_acc: 0.7290
Epoch 128/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7358Epoch 00127: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7360 - val_loss: 0.0023 - val_acc: 0.7266
Epoch 129/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7406Epoch 00128: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7412 - val_loss: 0.0025 - val_acc: 0.7313
Epoch 130/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7435Epoch 00129: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7453 - val_loss: 0.0023 - val_acc: 0.7243
Epoch 131/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7382Epoch 00130: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0018 - acc: 0.7401 - val_loss: 0.0023 - val_acc: 0.7407
Epoch 132/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7441Epoch 00131: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7453 - val_loss: 0.0023 - val_acc: 0.7313
Epoch 133/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7358Epoch 00132: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7354 - val_loss: 0.0024 - val_acc: 0.7360
Epoch 134/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7376Epoch 00133: val_loss improved from 0.00226 to 0.00217, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7383 - val_loss: 0.0022 - val_acc: 0.7313
Epoch 135/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7500Epoch 00134: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7500 - val_loss: 0.0024 - val_acc: 0.7336
Epoch 136/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7588Epoch 00135: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7599 - val_loss: 0.0022 - val_acc: 0.7336
Epoch 137/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7364Epoch 00136: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7377 - val_loss: 0.0025 - val_acc: 0.7500
Epoch 138/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7476Epoch 00137: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7471 - val_loss: 0.0026 - val_acc: 0.7360
Epoch 139/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7423Epoch 00138: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7424 - val_loss: 0.0024 - val_acc: 0.7383
Epoch 140/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7476Epoch 00139: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7471 - val_loss: 0.0023 - val_acc: 0.7383
Epoch 141/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7459Epoch 00140: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7477 - val_loss: 0.0023 - val_acc: 0.7220
Epoch 142/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7600Epoch 00141: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7588 - val_loss: 0.0026 - val_acc: 0.7360
Epoch 143/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7553Epoch 00142: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0017 - acc: 0.7547 - val_loss: 0.0022 - val_acc: 0.7383
Epoch 144/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7606Epoch 00143: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7611 - val_loss: 0.0023 - val_acc: 0.7430
Epoch 145/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7612Epoch 00144: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7629 - val_loss: 0.0022 - val_acc: 0.7336
Epoch 146/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7583Epoch 00145: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7570 - val_loss: 0.0025 - val_acc: 0.7383
Epoch 147/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7577Epoch 00146: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7582 - val_loss: 0.0025 - val_acc: 0.7430
Epoch 148/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7388Epoch 00147: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7389 - val_loss: 0.0023 - val_acc: 0.7313
Epoch 149/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7606Epoch 00148: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7611 - val_loss: 0.0023 - val_acc: 0.7360
Epoch 150/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7541Epoch 00149: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7535 - val_loss: 0.0028 - val_acc: 0.7360
Epoch 151/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7541Epoch 00150: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7564 - val_loss: 0.0022 - val_acc: 0.7290
Epoch 152/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7406Epoch 00151: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7418 - val_loss: 0.0026 - val_acc: 0.7266
Epoch 153/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7547Epoch 00152: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7558 - val_loss: 0.0023 - val_acc: 0.7453
Epoch 154/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7412Epoch 00153: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7401 - val_loss: 0.0027 - val_acc: 0.7266
Epoch 155/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7529Epoch 00154: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7529 - val_loss: 0.0023 - val_acc: 0.7360
Epoch 156/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7712Epoch 00155: val_loss improved from 0.00217 to 0.00205, saving model to my_model.h5
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7704 - val_loss: 0.0021 - val_acc: 0.7453
Epoch 157/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7482Epoch 00156: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7482 - val_loss: 0.0024 - val_acc: 0.7430
Epoch 158/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7518Epoch 00157: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7523 - val_loss: 0.0022 - val_acc: 0.7617
Epoch 159/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7665Epoch 00158: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7646 - val_loss: 0.0025 - val_acc: 0.7407
Epoch 160/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7471Epoch 00159: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7494 - val_loss: 0.0028 - val_acc: 0.7150
Epoch 161/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7671Epoch 00160: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7681 - val_loss: 0.0023 - val_acc: 0.7407
Epoch 162/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7518Epoch 00161: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7529 - val_loss: 0.0022 - val_acc: 0.7430
Epoch 163/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7524Epoch 00162: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7535 - val_loss: 0.0024 - val_acc: 0.7383
Epoch 164/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7642Epoch 00163: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7640 - val_loss: 0.0027 - val_acc: 0.7430
Epoch 165/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7618Epoch 00164: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7617 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 166/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7736Epoch 00165: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0015 - acc: 0.7728 - val_loss: 0.0023 - val_acc: 0.7243
Epoch 167/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7482Epoch 00166: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7494 - val_loss: 0.0022 - val_acc: 0.7664
Epoch 168/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7771Epoch 00167: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7757 - val_loss: 0.0024 - val_acc: 0.7617
Epoch 169/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7594Epoch 00168: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7617 - val_loss: 0.0021 - val_acc: 0.7243
Epoch 170/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7683Epoch 00169: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7693 - val_loss: 0.0022 - val_acc: 0.7453
Epoch 171/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7588Epoch 00170: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7588 - val_loss: 0.0023 - val_acc: 0.7570
Epoch 172/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7630Epoch 00171: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7640 - val_loss: 0.0024 - val_acc: 0.7547
Epoch 173/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7706Epoch 00172: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7710 - val_loss: 0.0022 - val_acc: 0.7430
Epoch 174/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7718Epoch 00173: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7722 - val_loss: 0.0023 - val_acc: 0.7617
Epoch 175/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7718Epoch 00174: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7710 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 176/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7783Epoch 00175: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7763 - val_loss: 0.0022 - val_acc: 0.7570
Epoch 177/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7529Epoch 00176: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0016 - acc: 0.7529 - val_loss: 0.0022 - val_acc: 0.7453
Epoch 178/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7677Epoch 00177: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7675 - val_loss: 0.0022 - val_acc: 0.7710
Epoch 179/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7812Epoch 00178: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7815 - val_loss: 0.0022 - val_acc: 0.7547
Epoch 180/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7771Epoch 00179: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7775 - val_loss: 0.0021 - val_acc: 0.7266
Epoch 181/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7724Epoch 00180: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7728 - val_loss: 0.0022 - val_acc: 0.7570
Epoch 182/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7765Epoch 00181: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7763 - val_loss: 0.0023 - val_acc: 0.7617
Epoch 183/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7736Epoch 00182: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7739 - val_loss: 0.0021 - val_acc: 0.7570
Epoch 184/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7748Epoch 00183: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7745 - val_loss: 0.0022 - val_acc: 0.7547
Epoch 185/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7677Epoch 00184: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7699 - val_loss: 0.0024 - val_acc: 0.7500
Epoch 186/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7736Epoch 00185: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7728 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 187/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7795Epoch 00186: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7786 - val_loss: 0.0024 - val_acc: 0.7500
Epoch 188/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7718Epoch 00187: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7728 - val_loss: 0.0021 - val_acc: 0.7336
Epoch 189/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7588Epoch 00188: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0014 - acc: 0.7576 - val_loss: 0.0024 - val_acc: 0.6519
Epoch 190/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7860Epoch 00189: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7862 - val_loss: 0.0023 - val_acc: 0.7664
Epoch 191/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7742Epoch 00190: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7728 - val_loss: 0.0023 - val_acc: 0.7383
Epoch 192/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7860Epoch 00191: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7850 - val_loss: 0.0029 - val_acc: 0.6939
Epoch 193/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7683Epoch 00192: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7681 - val_loss: 0.0024 - val_acc: 0.7336
Epoch 194/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7783Epoch 00193: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7792 - val_loss: 0.0022 - val_acc: 0.7360
Epoch 195/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7748Epoch 00194: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7745 - val_loss: 0.0022 - val_acc: 0.7103
Epoch 196/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7777Epoch 00195: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7775 - val_loss: 0.0023 - val_acc: 0.7500
Epoch 197/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7636Epoch 00196: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7634 - val_loss: 0.0021 - val_acc: 0.7430
Epoch 198/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7736Epoch 00197: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7739 - val_loss: 0.0023 - val_acc: 0.7477
Epoch 199/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7689Epoch 00198: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7687 - val_loss: 0.0048 - val_acc: 0.6986
Epoch 200/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7889Epoch 00199: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7868 - val_loss: 0.0021 - val_acc: 0.7430
Epoch 201/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7783Epoch 00200: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7792 - val_loss: 0.0021 - val_acc: 0.7570
Epoch 202/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7854Epoch 00201: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7856 - val_loss: 0.0022 - val_acc: 0.7664
Epoch 203/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7754Epoch 00202: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7751 - val_loss: 0.0025 - val_acc: 0.7640
Epoch 204/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7807Epoch 00203: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7810 - val_loss: 0.0021 - val_acc: 0.7664
Epoch 205/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7759Epoch 00204: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7751 - val_loss: 0.0021 - val_acc: 0.7664
Epoch 206/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7871Epoch 00205: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7856 - val_loss: 0.0021 - val_acc: 0.7664
Epoch 207/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7854Epoch 00206: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7833 - val_loss: 0.0021 - val_acc: 0.7547
Epoch 208/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7818Epoch 00207: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7815 - val_loss: 0.0023 - val_acc: 0.7313
Epoch 209/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7901Epoch 00208: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7903 - val_loss: 0.0021 - val_acc: 0.7617
Epoch 210/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7866Epoch 00209: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7856 - val_loss: 0.0021 - val_acc: 0.7407
Epoch 211/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7736Epoch 00210: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7739 - val_loss: 0.0022 - val_acc: 0.7640
Epoch 212/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7842Epoch 00211: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7839 - val_loss: 0.0024 - val_acc: 0.7570
Epoch 213/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7925Epoch 00212: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7921 - val_loss: 0.0022 - val_acc: 0.7173
Epoch 214/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7972Epoch 00213: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7950 - val_loss: 0.0022 - val_acc: 0.7780
Epoch 215/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7942Epoch 00214: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7938 - val_loss: 0.0021 - val_acc: 0.7734
Epoch 216/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7789Epoch 00215: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7775 - val_loss: 0.0023 - val_acc: 0.7477
Epoch 217/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7889Epoch 00216: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7897 - val_loss: 0.0021 - val_acc: 0.7547
Epoch 218/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7972Epoch 00217: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7979 - val_loss: 0.0024 - val_acc: 0.7290
Epoch 219/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7765Epoch 00218: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7745 - val_loss: 0.0022 - val_acc: 0.7383
Epoch 220/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7913Epoch 00219: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7903 - val_loss: 0.0022 - val_acc: 0.7617
Epoch 221/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7877Epoch 00220: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7868 - val_loss: 0.0021 - val_acc: 0.7407
Epoch 222/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7871Epoch 00221: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7868 - val_loss: 0.0023 - val_acc: 0.7126
Epoch 223/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7919Epoch 00222: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7915 - val_loss: 0.0021 - val_acc: 0.7500
Epoch 224/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7936Epoch 00223: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7938 - val_loss: 0.0024 - val_acc: 0.7547
Epoch 225/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7907Epoch 00224: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7921 - val_loss: 0.0022 - val_acc: 0.7734
Epoch 226/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8001Epoch 00225: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.8002 - val_loss: 0.0021 - val_acc: 0.7617
Epoch 227/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8001Epoch 00226: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.8002 - val_loss: 0.0021 - val_acc: 0.7617
Epoch 228/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7877Epoch 00227: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7880 - val_loss: 0.0022 - val_acc: 0.7570
Epoch 229/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7883Epoch 00228: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7891 - val_loss: 0.0023 - val_acc: 0.6822
Epoch 230/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7807Epoch 00229: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7798 - val_loss: 0.0023 - val_acc: 0.7523
Epoch 231/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7948Epoch 00230: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7938 - val_loss: 0.0023 - val_acc: 0.7570
Epoch 232/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7930Epoch 00231: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.7921 - val_loss: 0.0022 - val_acc: 0.7196
Epoch 233/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7995Epoch 00232: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0011 - acc: 0.8008 - val_loss: 0.0022 - val_acc: 0.7570
Epoch 234/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.8816e-04 - acc: 0.7936Epoch 00233: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.8870e-04 - acc: 0.7932 - val_loss: 0.0021 - val_acc: 0.7617
Epoch 235/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.7947e-04 - acc: 0.7919Epoch 00234: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.7838e-04 - acc: 0.7921 - val_loss: 0.0021 - val_acc: 0.7710
Epoch 236/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7877   Epoch 00235: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.9720e-04 - acc: 0.7886 - val_loss: 0.0022 - val_acc: 0.7150
Epoch 237/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7895Epoch 00236: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7897 - val_loss: 0.0024 - val_acc: 0.7593
Epoch 238/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7860Epoch 00237: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7862 - val_loss: 0.0022 - val_acc: 0.7780
Epoch 239/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7877Epoch 00238: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.9844e-04 - acc: 0.7880 - val_loss: 0.0021 - val_acc: 0.7266
Epoch 240/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.9701e-04 - acc: 0.7966Epoch 00239: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.9660e-04 - acc: 0.7967 - val_loss: 0.0021 - val_acc: 0.7313
Epoch 241/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7983Epoch 00240: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0010 - acc: 0.7991 - val_loss: 0.0021 - val_acc: 0.7804
Epoch 242/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7848Epoch 00241: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7827 - val_loss: 0.0024 - val_acc: 0.7523
Epoch 243/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7795Epoch 00242: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7792 - val_loss: 0.0021 - val_acc: 0.7710
Epoch 244/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.3900e-04 - acc: 0.7895Epoch 00243: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.3768e-04 - acc: 0.7903 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 245/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.3844e-04 - acc: 0.8007Epoch 00244: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.4048e-04 - acc: 0.7996 - val_loss: 0.0022 - val_acc: 0.7617
Epoch 246/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2091e-04 - acc: 0.8084Epoch 00245: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1967e-04 - acc: 0.8072 - val_loss: 0.0021 - val_acc: 0.7360
Epoch 247/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.1801e-04 - acc: 0.7925Epoch 00246: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1735e-04 - acc: 0.7932 - val_loss: 0.0021 - val_acc: 0.7383
Epoch 248/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.3495e-04 - acc: 0.7942Epoch 00247: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.3548e-04 - acc: 0.7932 - val_loss: 0.0021 - val_acc: 0.7827
Epoch 249/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.4961e-04 - acc: 0.7942Epoch 00248: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.5013e-04 - acc: 0.7944 - val_loss: 0.0021 - val_acc: 0.7173
Epoch 250/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2921e-04 - acc: 0.8007Epoch 00249: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.2777e-04 - acc: 0.8014 - val_loss: 0.0022 - val_acc: 0.7266
Epoch 251/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.6818e-04 - acc: 0.8072Epoch 00250: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.6736e-04 - acc: 0.8067 - val_loss: 0.0022 - val_acc: 0.7664
Epoch 252/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.1351e-04 - acc: 0.8101Epoch 00251: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1228e-04 - acc: 0.8090 - val_loss: 0.0021 - val_acc: 0.7780
Epoch 253/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2318e-04 - acc: 0.8037Epoch 00252: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.2267e-04 - acc: 0.8049 - val_loss: 0.0021 - val_acc: 0.7640
Epoch 254/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.5299e-04 - acc: 0.7895Epoch 00253: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.5396e-04 - acc: 0.7897 - val_loss: 0.0021 - val_acc: 0.7500
Epoch 255/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7942    Epoch 00254: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.9895e-04 - acc: 0.7950 - val_loss: 0.0022 - val_acc: 0.7640
Epoch 256/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.6039e-04 - acc: 0.8048Epoch 00255: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.5903e-04 - acc: 0.8055 - val_loss: 0.0021 - val_acc: 0.7780
Epoch 257/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7718Epoch 00256: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7716 - val_loss: 0.0032 - val_acc: 0.7617
Epoch 258/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.4280e-04 - acc: 0.8125Epoch 00257: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.4126e-04 - acc: 0.8119 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 259/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.6907e-04 - acc: 0.8084Epoch 00258: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.6916e-04 - acc: 0.8084 - val_loss: 0.0023 - val_acc: 0.7126
Epoch 260/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.8296e-04 - acc: 0.7925Epoch 00259: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.8155e-04 - acc: 0.7944 - val_loss: 0.0023 - val_acc: 0.7033
Epoch 261/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.8462e-04 - acc: 0.8048Epoch 00260: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.8381e-04 - acc: 0.8043 - val_loss: 0.0021 - val_acc: 0.7360
Epoch 262/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2954e-04 - acc: 0.8066Epoch 00261: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.3064e-04 - acc: 0.8072 - val_loss: 0.0023 - val_acc: 0.7804
Epoch 263/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.0556e-04 - acc: 0.8001Epoch 00262: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.0474e-04 - acc: 0.7991 - val_loss: 0.0021 - val_acc: 0.7593
Epoch 264/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.8992e-04 - acc: 0.7995Epoch 00263: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.9054e-04 - acc: 0.7991 - val_loss: 0.0021 - val_acc: 0.7453
Epoch 265/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.9533e-04 - acc: 0.7913Epoch 00264: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.9483e-04 - acc: 0.7915 - val_loss: 0.0021 - val_acc: 0.7757
Epoch 266/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.6882e-04 - acc: 0.8066Epoch 00265: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.6942e-04 - acc: 0.8061 - val_loss: 0.0022 - val_acc: 0.7850
Epoch 267/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.1107e-04 - acc: 0.8125Epoch 00266: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1164e-04 - acc: 0.8131 - val_loss: 0.0021 - val_acc: 0.7780
Epoch 268/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.3445e-04 - acc: 0.7960Epoch 00267: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.3606e-04 - acc: 0.7973 - val_loss: 0.0022 - val_acc: 0.7266
Epoch 269/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.0676e-04 - acc: 0.7948Epoch 00268: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.0681e-04 - acc: 0.7961 - val_loss: 0.0022 - val_acc: 0.7757
Epoch 270/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.9725e-04 - acc: 0.8019Epoch 00269: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.9957e-04 - acc: 0.8020 - val_loss: 0.0021 - val_acc: 0.7500
Epoch 271/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.1476e-04 - acc: 0.8119Epoch 00270: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1548e-04 - acc: 0.8131 - val_loss: 0.0023 - val_acc: 0.7780
Epoch 272/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2273e-04 - acc: 0.7995Epoch 00271: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.2188e-04 - acc: 0.7996 - val_loss: 0.0022 - val_acc: 0.7874
Epoch 273/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.0082e-04 - acc: 0.8042Epoch 00272: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.0140e-04 - acc: 0.8043 - val_loss: 0.0022 - val_acc: 0.7243
Epoch 274/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.8962e-04 - acc: 0.8125Epoch 00273: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.8812e-04 - acc: 0.8125 - val_loss: 0.0022 - val_acc: 0.7430
Epoch 275/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.9818e-04 - acc: 0.7995Epoch 00274: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.9861e-04 - acc: 0.7996 - val_loss: 0.0022 - val_acc: 0.7687
Epoch 276/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.2898e-04 - acc: 0.7954Epoch 00275: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.2945e-04 - acc: 0.7956 - val_loss: 0.0022 - val_acc: 0.7196
Epoch 277/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.4479e-04 - acc: 0.7983Epoch 00276: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.4408e-04 - acc: 0.7985 - val_loss: 0.0024 - val_acc: 0.7033
Epoch 278/300
1696/1712 [============================>.] - ETA: 0s - loss: 9.1054e-04 - acc: 0.8143Epoch 00277: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 9.1056e-04 - acc: 0.8143 - val_loss: 0.0022 - val_acc: 0.7407
Epoch 279/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7895Epoch 00278: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0012 - acc: 0.7891 - val_loss: 0.0024 - val_acc: 0.7500
Epoch 280/300
1696/1712 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7901Epoch 00279: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 0.0013 - acc: 0.7915 - val_loss: 0.0021 - val_acc: 0.7617
Epoch 281/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.2545e-04 - acc: 0.8101Epoch 00280: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.2548e-04 - acc: 0.8113 - val_loss: 0.0021 - val_acc: 0.7687
Epoch 282/300
1696/1712 [============================>.] - ETA: 0s - loss: 7.9539e-04 - acc: 0.8048Epoch 00281: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 7.9640e-04 - acc: 0.8043 - val_loss: 0.0021 - val_acc: 0.7430
Epoch 283/300
1696/1712 [============================>.] - ETA: 0s - loss: 7.9804e-04 - acc: 0.8090Epoch 00282: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 7.9509e-04 - acc: 0.8078 - val_loss: 0.0021 - val_acc: 0.7360
Epoch 284/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.0407e-04 - acc: 0.8243Epoch 00283: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.0187e-04 - acc: 0.8254 - val_loss: 0.0021 - val_acc: 0.7827
Epoch 285/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.1348e-04 - acc: 0.8278Epoch 00284: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.1276e-04 - acc: 0.8259 - val_loss: 0.0021 - val_acc: 0.7430
Epoch 286/300
1696/1712 [============================>.] - ETA: 0s - loss: 7.9723e-04 - acc: 0.8190Epoch 00285: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 7.9579e-04 - acc: 0.8189 - val_loss: 0.0021 - val_acc: 0.7173
Epoch 287/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.0159e-04 - acc: 0.8225Epoch 00286: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.0276e-04 - acc: 0.8230 - val_loss: 0.0021 - val_acc: 0.7874
Epoch 288/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.0410e-04 - acc: 0.8137Epoch 00287: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.0740e-04 - acc: 0.8119 - val_loss: 0.0022 - val_acc: 0.7243
Epoch 289/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.0580e-04 - acc: 0.8196Epoch 00288: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.0366e-04 - acc: 0.8207 - val_loss: 0.0023 - val_acc: 0.7383
Epoch 290/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.3489e-04 - acc: 0.8101Epoch 00289: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.3455e-04 - acc: 0.8107 - val_loss: 0.0021 - val_acc: 0.7523
Epoch 291/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.2583e-04 - acc: 0.8178Epoch 00290: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.2468e-04 - acc: 0.8160 - val_loss: 0.0021 - val_acc: 0.7593
Epoch 292/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.1720e-04 - acc: 0.8007Epoch 00291: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.1496e-04 - acc: 0.8002 - val_loss: 0.0022 - val_acc: 0.7780
Epoch 293/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.1343e-04 - acc: 0.8190Epoch 00292: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.1320e-04 - acc: 0.8195 - val_loss: 0.0021 - val_acc: 0.7757
Epoch 294/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.3696e-04 - acc: 0.8013Epoch 00293: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.3710e-04 - acc: 0.8020 - val_loss: 0.0021 - val_acc: 0.7383
Epoch 295/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.1851e-04 - acc: 0.8208Epoch 00294: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.1839e-04 - acc: 0.8218 - val_loss: 0.0022 - val_acc: 0.7523
Epoch 296/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.3222e-04 - acc: 0.8131Epoch 00295: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.3132e-04 - acc: 0.8143 - val_loss: 0.0022 - val_acc: 0.7173
Epoch 297/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.4421e-04 - acc: 0.8143Epoch 00296: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.4528e-04 - acc: 0.8143 - val_loss: 0.0021 - val_acc: 0.7430
Epoch 298/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.4043e-04 - acc: 0.8190Epoch 00297: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.4128e-04 - acc: 0.8166 - val_loss: 0.0022 - val_acc: 0.7477
Epoch 299/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.7776e-04 - acc: 0.8084Epoch 00298: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.7784e-04 - acc: 0.8078 - val_loss: 0.0021 - val_acc: 0.7757
Epoch 300/300
1696/1712 [============================>.] - ETA: 0s - loss: 8.7308e-04 - acc: 0.8261Epoch 00299: val_loss did not improve
1712/1712 [==============================] - 3s - loss: 8.7488e-04 - acc: 0.8254 - val_loss: 0.0021 - val_acc: 0.7874

Step 7: Visualize the Loss and Test Predictions

(IMPLEMENTATION) Answer a few questions and visualize the loss

Question 1: Outline the steps you took to get to your final neural network architecture and your reasoning at each step.

Answer: Firstly, at this stage of the nanodegree I collected quite a bit of experience on experimenting with CNNs, so I knew that my architecture would be divided in 3 parts: 1. a number of Conv-Pool passes (2 or 3) 2. a flattening phase (which I found to be very effective when performed with GAP) and 3. a number of densely connected layers, at least 2 as the problem is non-linear. From there, I experimented with the architecture and its hyperparameters on a subset of the data, to find out which parameter values were more promising and discard the others. I tried increasing and decreasing the depth of the network, and observed the training and test accuracies obtained.

I noticed that the best result on the convolutional part of the network is obtained with 3 Conv-Pool passes, 4 passes would only slow it down and add no benefit to the accuracy of the model. Based on the course material and articles linked, I progressively increased the number of filters, while reducing their size. I used "same" padding to squeeze every bit of information out, although in hindsight, this may not add great benefit as - objectively - facial landmarks are concentrated around the center of the image, and are never at the border, which is where padding is relevant.

In the densely connected part of the network, adding a further densely connected layer increased overfitting, as the accuracy on the test set plateaued at 70% while the train accuracy was at 90%, and test accuracy started even slightly decreasing beyond 250-300 epochs.

Both at the convolutional and densely connected stage I did not find that activations improved the result. ReLU is normally good, but unusable in this case as values are normalized between -1 and 1. Which means that any value below 0 would have been turned into a 0 (Out of curiosity I tried it out and accuracy was extremely low). Tanh and sigmoid did not improve the model. I was curious to try "selu" (self normalizing networks) but this has not made it into the keras version installed by the GPU AWS instance.

The GAP layer is my flattening layer of choice: it takes data from the input tensor and outputs a global average for each feature. Which means that it's an intelligent Flatten(), which simply flattens the data. I found that GAP is the perfect transition between CONV-POOL layer sets and Dense.

Question 2: Defend your choice of optimizer. Which optimizers did you test, and how did you determine which worked best?

Answer: I tried them all out. I chose adamax as it is the best performing of the adaptive optimizers. SGD did not performed well when compared to Adamax or RMSprop. Nadam caused me a very wierd issue (see the issue i opened on the forum https://discussions.udacity.com/t/sudden-catastrophic-drop-in-accuracy-during-training/340960), even though it was very promising. In the end it was down to Adamax and RMSprop, and while they are on similar performance levels, Adamax yielded the higher test accuracy. To validate my choice, I used the GridSearchCV class of sklearn (see this post for how i implemented it: http://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/), passing all the optimizers in. I would have liked to perform GridSearch on all hyperparameters (learning rate for the optimizer, decay, number of nodes in the hidden dense layers, filters in the conv layers etc.), but that would have been an extremely lengthy process.

Use the code cell below to plot the training and validation loss of your neural network. You may find this resource useful.

In [35]:
## TODO: Visualize the training and validation loss of your neural network
# summarize history for accuracy
plt.plot(hist.history['acc'])
plt.plot(hist.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='lower left')
plt.show()
# summarize history for loss
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper right')
plt.show()

Question 3: Do you notice any evidence of overfitting or underfitting in the above plot? If so, what steps have you taken to improve your model? Note that slight overfitting or underfitting will not hurt your chances of a successful submission, as long as you have attempted some solutions towards improving your model (such as regularization, dropout, increased/decreased number of layers, etc).

Answer: I noticed overfitting occurring in different measure in all the models I trained (20+). Adding more conv-pool layers increased overfitting somewhat, adding more dense layers increased overfitting quite a lot. Regularization reduced overfitting but it also decreased overall accuracy (this was my empirical find, I might have implemented it in the wrong layers, I was using L1 regularization in the Dense layers). What really reduced overfitting was the addition of Dropout layers. I found 0.2 to be an optimal value, contributing to keeping train/test on similar levels while not damaging accuracy.

Visualize a Subset of the Test Predictions

Execute the code cell below to visualize your model's predicted keypoints on a subset of the testing images.

In [36]:
y_test = model.predict(X_test)
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_test[i], y_test[i], ax)

Step 8: Complete the pipeline

With the work you did in Sections 1 and 2 of this notebook, along with your freshly trained facial keypoint detector, you can now complete the full pipeline. That is given a color image containing a person or persons you can now

  • Detect the faces in this image automatically using OpenCV
  • Predict the facial keypoints in each face detected in the image
  • Paint predicted keypoints on each face detected

In this Subsection you will do just this!

(IMPLEMENTATION) Facial Keypoints Detector

Use the OpenCV face detection functionality you built in previous Sections to expand the functionality of your keypoints detector to color images with arbitrary size. Your function should perform the following steps

  1. Accept a color image.
  2. Convert the image to grayscale.
  3. Detect and crop the face contained in the image.
  4. Locate the facial keypoints in the cropped image.
  5. Overlay the facial keypoints in the original (color, uncropped) image.

Note: step 4 can be the trickiest because remember your convolutional network is only trained to detect facial keypoints in $96 \times 96$ grayscale images where each pixel was normalized to lie in the interval $[0,1]$, and remember that each facial keypoint was normalized during training to the interval $[-1,1]$. This means - practically speaking - to paint detected keypoints onto a test face you need to perform this same pre-processing to your candidate face - that is after detecting it you should resize it to $96 \times 96$ and normalize its values before feeding it into your facial keypoint detector. To be shown correctly on the original image the output keypoints from your detector then need to be shifted and re-normalized from the interval $[-1,1]$ to the width and height of your detected face.

When complete you should be able to produce example images like the one below

<img src="images/obamas_with_keypoints.png" width=1000 height=1000/>

In [37]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

image_copy = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# plot our image
fig = plt.figure(figsize = (9,9))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('image copy')
ax1.imshow(image_copy, cmap='gray')
Out[37]:
<matplotlib.image.AxesImage at 0x7f9f2c316dd8>
In [38]:
### TODO: Use the face detection code we saw in Section 1 with your trained conv-net 
## TODO : Paint the predicted keypoints on the test image
model.load_weights("./adamax_dropout_300e.h5")
face_cascade = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")

faces = face_cascade.detectMultiScale(image_copy, 1.25, 6)

def denormalize(value):
    return int(round(value * 48 + 48))

image_with_landmarks = image.copy()

for (x, y, w, h) in faces:
    copy = image_copy.copy()
    roi = copy[y:y+h, x:x+w]
    resized = cv2.resize(roi, (96, 96))
    pred = np.array([resized])/255.
    pred = pred[..., np.newaxis]
    np.moveaxis(pred, 1, 3)
    y_pred = model.predict(pred)
    den_pred = list(map(denormalize, y_pred[0]))
    print("Original w: {}, ratio: {}".format(w, float(w/96)))
    scale = w / 96
    for i in range(0, 15):
        cx = x + int((den_pred[i * 2]) * scale)
        cy = y + int((den_pred[i * 2 + 1]) * scale)
        cv2.circle(image_with_landmarks, (cx, cy), 1, (0, 255, 0), 3)

    print(y_pred, den_pred)
Original w: 175, ratio: 1.8229166666666667
[[ 0.38963631 -0.21730307 -0.42678547 -0.21010162  0.23753646 -0.18715686
   0.58348244 -0.20586576 -0.23766708 -0.17966782 -0.61728543 -0.19587585
   0.19971514 -0.3499676   0.67215633 -0.39154366 -0.14522411 -0.36946714
  -0.73545587 -0.36727935  0.10681724  0.35895684  0.43493947  0.53395236
  -0.45698708  0.55740076  0.03646723  0.60426569  0.02475408  0.79497004]] [67, 38, 28, 38, 59, 39, 76, 38, 37, 39, 18, 39, 58, 31, 80, 29, 41, 30, 13, 30, 53, 65, 69, 74, 26, 75, 50, 77, 49, 86]
Original w: 166, ratio: 1.7291666666666667
[[ 0.40777144 -0.20645891 -0.35980344 -0.15892121  0.24423625 -0.17404979
   0.58520746 -0.19737026 -0.21492536 -0.14475393 -0.52172464 -0.12878448
   0.11149586 -0.32231387  0.70131826 -0.35695052 -0.19492638 -0.2814616
  -0.66817188 -0.2674267  -0.07791466  0.2716575   0.40900433  0.60444349
  -0.30937654  0.63591069  0.01663742  0.59687757  0.02239933  0.7651028 ]] [68, 38, 31, 40, 60, 40, 76, 39, 38, 41, 23, 42, 53, 33, 82, 31, 39, 34, 16, 35, 44, 61, 68, 77, 33, 79, 49, 77, 49, 85]
In [39]:
# plot our image
fig = plt.figure(figsize = (10, 10))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('image copy')
ax1.imshow(image_with_landmarks)
Out[39]:
<matplotlib.image.AxesImage at 0x7f9f372cff60>

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add facial keypoint detection to your laptop camera - as illustrated in the gif below.

<img src="images/facial_keypoint_test.gif" width=400 height=300/>

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for keypoint detection and marking in the previous exercise and you should be good to go!

In [2]:
import cv2
import time 
from keras.models import load_model

def denormalize(value):
    return int(round(value * 48 + 48))

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)
    model = load_model("adamax_dropout_300e.h5")
    face_c = cv2.CascadeClassifier("detector_architectures/haarcascade_frontalface_default.xml")
    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # keep video stream open
    while rval:
        # plot image from camera with detections marked
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = face_c.detectMultiScale(gray, 1.25, 6)
        for (x, y, w, h) in faces:
            roi = gray[y:y+h, x:x+w]
            resized = cv2.resize(roi, (96, 96))
            raw_pred = model.predict(resized)
            den_pred = list(map(denormalize, raw_pred))
            scale = w / 96
            for i in range(0, 15):
                cx = x + int((den_pred[i * 2]) * scale)
                cy = y + int((den_pred[i * 2 + 1]) * scale)
                cv2.circle(frame, (cx, cy), 1, (0, 255, 0), 3)
            
            
        cv2.imshow("face detection activated", frame)
        
        # exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # destroy windows
            cv2.destroyAllWindows()
            
            # hack from stack overflow for making sure window closes on osx --> https://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()  
Using TensorFlow backend.
In [ ]:
# Run your keypoint face painter
laptop_camera_go()

(Optional) Further Directions - add a filter using facial keypoints

Using your freshly minted facial keypoint detector pipeline you can now do things like add fun filters to a person's face automatically. In this optional exercise you can play around with adding sunglasses automatically to each individual's face in an image as shown in a demonstration image below.

<img src="images/obamas_with_shades.png" width=1000 height=1000/>

To produce this effect an image of a pair of sunglasses shown in the Python cell below.

In [ ]:
# Load in sunglasses image - note the usage of the special option
# cv2.IMREAD_UNCHANGED, this option is used because the sunglasses 
# image has a 4th channel that allows us to control how transparent each pixel in the image is
sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)

# Plot the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.imshow(sunglasses)
ax1.axis('off');

This image is placed over each individual's face using the detected eye points to determine the location of the sunglasses, and eyebrow points to determine the size that the sunglasses should be for each person (one could also use the nose point to determine this).

Notice that this image actually has 4 channels, not just 3.

In [ ]:
# Print out the shape of the sunglasses image
print ('The sunglasses image has shape: ' + str(np.shape(sunglasses)))

It has the usual red, blue, and green channels any color image has, with the 4th channel representing the transparency level of each pixel in the image. Here's how the transparency channel works: the lower the value, the more transparent the pixel will become. The lower bound (completely transparent) is zero here, so any pixels set to 0 will not be seen.

This is how we can place this image of sunglasses on someone's face and still see the area around of their face where the sunglasses lie - because these pixels in the sunglasses image have been made completely transparent.

Lets check out the alpha channel of our sunglasses image in the next Python cell. Note because many of the pixels near the boundary are transparent we'll need to explicitly print out non-zero values if we want to see them.

In [ ]:
# Print out the sunglasses transparency (alpha) channel
alpha_channel = sunglasses[:,:,3]
print ('the alpha channel here looks like')
print (alpha_channel)

# Just to double check that there are indeed non-zero values
# Let's find and print out every value greater than zero
values = np.where(alpha_channel != 0)
print ('\n the non-zero values of the alpha channel look like')
print (values)

This means that when we place this sunglasses image on top of another image, we can use the transparency channel as a filter to tell us which pixels to overlay on a new image (only the non-transparent ones with values greater than zero).

One last thing: it's helpful to understand which keypoint belongs to the eyes, mouth, etc. So, in the image below, we also display the index of each facial keypoint directly on the image so that you can tell which keypoints are for the eyes, eyebrows, etc.

<img src="images/obamas_points_numbered.png" width=500 height=500/>

With this information, you're well on your way to completing this filtering task! See if you can place the sunglasses automatically on the individuals in the image loaded in / shown in the next Python cell.

In [ ]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Plot the image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
In [ ]:
## (Optional) TODO: Use the face detection code we saw in Section 1 with your trained conv-net to put
## sunglasses on the individuals in our test image

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add the sunglasses filter to your laptop camera - as illustrated in the gif below.

<img src="images/mr_sunglasses.gif" width=250 height=250/>

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for adding sunglasses to someone's face in the previous optional exercise and you should be good to go!

In [ ]:
import cv2
import time 
from keras.models import load_model
import numpy as np

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [ ]:
# Load facial landmark detector model
model = load_model('my_model.h5')

# Run sunglasses painter
laptop_camera_go()